<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="600px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel :show-add-button="false" :show-search-button="true"
                    labelWidth="73" @search="search" :left="true">
        <el-form-item label="运营商:" prop="operatoruid">
          <el-select v-model="filters.operatoruid" filterable clearable placeholder="请选择运营商">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in operator"
              :key="item.operatoruid"
              :label="item.operatorname"
              :value="item.operatoruid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="供货商:" prop="useruuid"  >
          <el-select v-model="filters.upuseruuid" clearable placeholder="请选择供货商" filterable multiple collapse-tags>
            <el-option value="0" label="全部">全部</el-option>
            <el-option v-if="users && users.length > 0"
                       v-for="item in usersUp"
                       :key="item.user.useruuid"
                       :label="item.user.username"
                       :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分销商:" prop="useruuid">
          <el-select v-model="filters.useruuid" clearable placeholder="请选择分销商" filterable multiple collapse-tags>
            <el-option value="0" label="全部">全部</el-option>
            <el-option v-if="users && users.length > 0"
                       v-for="item in users"
                       :key="item.user.useruuid"
                       :label="item.user.username"
                       :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="省份:" prop="provinceuuid">
          <el-select v-model="filters.provinceuuid" filterable clearable placeholder="请选择省份" >
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in info"
              :key="item.provincename"
              :label="item.provincename"
              :value="item.provincename">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务类型:" prop="busuuid">
          <el-select v-model="filters.busuuid" filterable clearable placeholder="请选择业务类型">
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in bus"
              :key="item.busuuid"
              :label="item.busname"
              :value="item.busuuid">
            </el-option>
          </el-select>
        </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="false"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
        </template>
      </data-table>
    </template>

    <template #dialog>
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import util from '../../../utils/util'
import {findPageOperator,findAllUpShopInfo,findAllDownShopInfo,findAllPro,findAllBus} from '@/api/utilsapi'
import {findPageProductDown} from '@/api/upapi'

export default {
  name: 'downProductMatch',
  mixins: [
    baseMixin({
      idName: 'id',
      findData:findPageProductDown,
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      pageShow: true,
      dialogData:{},
      users:[],
      tableColumnAttributes: [
        // 供货商	分销商	运营商	运营商	业务类型
        { name: '供货商', value: 'username'},
        { name: '分销商', value: 'downname' },
        { name: '运营商', value: 'provincename' },
        { name: '省份', value: 'provincename' },
        { name: '业务类型', value: 'busname' },
      ],
      filters: {
        upuseruuid:'',
        useruuid:'',
        operatoruid:'',
        provinceuuid:'',
        busuuid:'',
      },
      users:[],
      usersUp:[],
      info:[],
      bus:[],
      operator: [],
    }
  },
  methods: {
    async search(form){
      let para = {
        start: 0,
        pageSize: 10,
        useruuid: this.filters.useruuid == "0" ? "" : this.filters.useruuid,
        upuseruuid: this.filters.upuseruuid == "0" ? "" : this.filters.upuseruuid,
        operatoruid:this.filters.operatoruid == "0" ? "" : this.filters.operatoruid,
        provinceuuid:this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
        busuuid:this.filters.busuuid == "0" ? "" : this.filters.busuuid,
      };
      this.searchOptions = para;
      this.setTableData()
    },
    async findAllUpShopInfo(){
      let para = {
        test:''
      };
      const result = await findAllUpShopInfo(para);
      if(result.data){
        this.usersUp = result.data;
      }
    },
    async findPageOperator(){
      let para = {
        start: 1,
        pageSize:101,
        operatorname:'',
      };
      findPageOperator(para).then((datas) => {
        let { message, code, data } = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else if(data && data.result){
          this.operator = data.result;
        }
      });
    },
    findAllPro(){
      let para = {
        test:''
      };
      findAllPro(para).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error');
        } else {
          this.info = data;
        }
      });
    },
    findAllBus(){
      let para = {
        test:''
      };
      findAllBus(para).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else {
          this.bus = data;
        }
      });
    },
    findAllDownShopInfo(){
      let para = {useruuid: this.$store.getters.useruuid};
      findAllDownShopInfo(para).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else {
          if(data){
            this.users = data;
          }
        }
      });
    }

  },
  mounted() {
    this.findAllDownShopInfo();
    this.findAllUpShopInfo();
    this.findPageOperator();
    this.findAllPro();
    this.findAllBus();
  }
}
</script>
